﻿@{
    ViewData["Title"] = "Home Page";
}
<div class="row" style="margin-top:20px">
    <div class="col-md-12">
        <div class="col-md-9">
            <input id="sip" type="text" placeholder="服务器IP" value="" />
            <input id="sname" type="text" placeholder="账号" value="" />
            <input id="spassword" type="password" placeholder="密码" value="" />
        </div>
        <div class="col-md-3">
            <button type="button" class="btn btn-primary" onclick="Open()">连接</button>
        </div>
    </div>
    <div class="col-md-12">
        <div class="col-md-3">
            <input id="sCmd" type="text" placeholder="执行命令" value="" />
        </div>
        <div class="col-md-3">
            <button type="button" class="btn btn-primary" onclick="Cmd()">执行</button>
        </div>
    </div>
    <h2>Log</h2>
    <div class="col-md-12">
        <textarea rows="3" cols="100" id="textarea1"></textarea>
    </div>
</div>
<script>
    function Open() {
        var ip = $("#sip").val();
        var name = $("#sname").val();
        var password = $("#spassword").val();
        $.ajax({
            url: "/api/ssh/ConnectShell?ip=" + ip + "&name=" + name + "&password=" + password,
            type: "get",
            success: function (data) {
                $("#textarea1").val((new Date()).toLocaleTimeString() + "\r\n"+ data + "\r\n" + $("#textarea1").val() + "\r\n");
            }
        });
    }
    function Cmd(cmd) {
        var ip = $("#sip").val();
        if (cmd === "" || cmd == undefined) {
            cmd = $("#sCmd").val();
        }
        $.ajax({
            url: "/api/ssh/RunCommand?ip=" + ip + "&cmd=" + cmd,
            type: "get",
            success: function (data) {
                $("#textarea1").val((new Date()).toLocaleTimeString() + "\r\n执行："+cmd+"\r\n" + data + "\r\n" + $("#textarea1").val() + "\r\n");
            }
        });
    }
</script>